package com.tencent.basic.config;

import com.tencent.basic.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器的配置类
 */
@Configuration // 声明当前类是一个配置类 代替原来的xml
public class MyWebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 相当于原来xml中的 <interceptors>....<interceptors/>
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**") // 拦截所有请求
                // 放行登录 - 有管理员和用户 所以/**
                .excludePathPatterns("/login/**")
                // 放行注册 - 用户手机号+邮箱注册  图片+手机+邮箱验证码
                .excludePathPatterns("/user/*/register", "/verifyCode/**", "/user/active/**")
                // 放行店铺入驻 及其相关 图片上传 店铺激活
                .excludePathPatterns("/fastDfs", "/shop/settlement", "/shop/active/**")
                //放行swagger
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");
    }
}
